/* Kanvas Paint and Drawing Tool.
 * Copyright (C) 2011 Darryl Wallace
 * wallacdj@gmail.com / darryl@wallynet.ca
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "kanvas.h"
#include "LibKanvas/CanvasView.h"
#include "LibKanvas/ViewFrame.h"
#include "LibKanvas/Canvas.h"
#include "LibKanvas/LayerItem.h"
#include "PluginManager.h"
#include "MouseToolsWidget.h"

Kanvas::Kanvas(PluginManager *pmanager, QWidget *parent, Qt::WFlags flags)
        : QMainWindow(parent, flags),
          _pluginManager(pmanager)
{
    _vframe = new ViewFrame(this);
    setCentralWidget(_vframe);
    QVBoxLayout *_frame_layout = new QVBoxLayout();
    _canvasView = new CanvasView();
    _canvasView->setActive(true);
    Canvas *c = new Canvas();
    _canvasView->setScene(c);
    c->addLayer();
    connect(_canvasView,SIGNAL(zoomFactorChanged(qreal)),
            c, SLOT(setCurrentZoomFactor(qreal)));
    LayerItem *l=c->getLayer(0);
    if (l)
        l->fillImage(Qt::white);

    _frame_layout->addWidget(_canvasView);
    _vframe->setLayout(_frame_layout);

    _mouseToolsWidget = new MouseToolsWidget(pmanager, this);
    addDockWidget(Qt::RightDockWidgetArea , _mouseToolsWidget, Qt::Horizontal);
    connect(_mouseToolsWidget,SIGNAL(toolSelectionChanged()),
            SLOT(getCurrentTool()));
}

Kanvas::~Kanvas()
{

}

void Kanvas::getCurrentTool()
{
    _currentTool=_mouseToolsWidget->currentTool();
    Canvas *c = qobject_cast<Canvas *>(_canvasView->scene());
    c->setCurrentTool(_currentTool);
}
